Form fields can either be removed one at a time or all at once. For flattening form fields (preserving the data but removing the form fields structure) please see the Form Flattening topic.
Removing a form field one at a time is done by setting the field Output property to the FormFieldOutput.Remove.
The following example demonstrates how to remove an individual form field using Form Field's Output property:
[Java]
MergeDocument document = new MergeDocument("[PhysicalPath]/Document1.pdf");
document.getForm().getFields().getFormField(0).setOutput(FormFieldOutput.REMOVE);
document.draw("[PhysicalPath]/MyDocument.pdf");
If it is known, prior to the merging of a PDF document, that all form fields need to be removed, then the form fields should be removed using the MergeOptions method.
The following example leaves out all form fields when the PDF is merged in:
[Java]
MergeOptions mergeOptions = new MergeOptions();
mergeOptions.setFormFields(false);
MergeDocument document = new MergeDocument("[PhysicalPath]/Document1.pdf", mergeOptions );
document.draw("[PhysicalPath]/MyDocument.pdf");
Alternatively, if the form fields are left in the MergeDocument, it can be specified at that the form fields be left off the final output of the PDF by using the Form's Output property.
The following example demonstrates how to remove all the form fields using Form's Output property:
[Java]
MergeDocument document = new MergeDocument("C:\\Document1.pdf");
document.getForm().setOutput(FormOutput.REMOVE);
document.draw("C:\\MyDocument_withoutFields.pdf");